package dome1;

import java.text.AttributedCharacterIterator;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 王圆豪
 * Date: 2024-06-12
 * Time: 14:31
 */
class Good{
    private String num;
    private String name;
    private double price;

    public Good(String num, String name, double price) {
        this.num = num;
        this.name = name;
        this.price = price;
    }

    public String getNum() {
        return num;
    }

    public String getName() {
        return name;
    }

    public double getPrice() {
        return price;
    }

    @Override
    public String toString() {
        return num + ',' +
                name + ',' +
                price
                ;
    }
}

class Goods{
    private String name;
    private double price;

    public Goods(String name, double price) {
        this.name = name;
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    @Override
    public String toString() {
        return name + "," + price;
    }
}

class Rectangle{
    private double width = 1;
    private double height = 1;

    public Rectangle(double width, double height) {
        this.width = width;
        this.height = height;
    }

    public Rectangle() {

    }

    public double getArea() {
        return this.height * this.width;
    }

    public double getPerimeter() {
        return 2 * this.width + 2 * this.height;
    }

    @Override
    public String toString() {
        return this.width + " " + this.height + " "
                + getArea() + " " + getPerimeter();
    }
}

class Birthday{
    private int year;
    private int month;
    private int day;

    public Birthday(int year, int month, int day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public int getDay() {
        return day;
    }

    public void setDay(int day) {
        this.day = day;
    }

    public int getAge() {
        int age = 2017 - this.year;
        if (this.month < 12) {
            return age;
        } else {
            if (this.day < 25) {
                return age;
            } else {
                return age + 1;
            }
        }
    }
}

class Complex{
    private double RealPart;
    private double ImaginaryPart;

    public Complex(double realPart, double imaginaryPart) {
        RealPart = realPart;
        ImaginaryPart = imaginaryPart;
    }

    public Complex() {

    }

    public String add(Complex c2) {
        Complex c3 = new Complex();
        c3.RealPart = this.RealPart + c2.RealPart;
        c3.ImaginaryPart = this.ImaginaryPart + c2.ImaginaryPart;
        if (c3.RealPart == 0) {
            return c3.ImaginaryPart + "i";
        } else if (c3.ImaginaryPart == 0) {
            return "" + c3.RealPart;
        } else{
            return c3.RealPart + (c3.ImaginaryPart < 0 ? "" : "+") + c3.ImaginaryPart + "i";
        }
    }

    public String sub(Complex c2) {
        Complex c3 = new Complex();
        c3.RealPart = this.RealPart - c2.RealPart;
        c3.ImaginaryPart = this.ImaginaryPart - c2.ImaginaryPart;
        if (c3.RealPart == 0) {
            return c3.ImaginaryPart + "i";
        } else if (c3.ImaginaryPart == 0) {
            return "" + c3.RealPart;
        } else{
            return c3.RealPart + (c3.ImaginaryPart < 0 ? "" : "+") + c3.ImaginaryPart + "i";
        }
    }

    public double getRealPart() {
        return RealPart;
    }

    public void setRealPart(double realPart) {
        RealPart = realPart;
    }

    public double getImaginaryPart() {
        return ImaginaryPart;
    }

    public void setImaginaryPart(double imaginaryPart) {
        ImaginaryPart = imaginaryPart;
    }

    @Override
    public String toString() {
        return this.RealPart + (this.ImaginaryPart < 0 ? "" : "+") + this.ImaginaryPart + "i";
    }
}

class BankBusiness{
    public static String bankName = "中国银行";
    private String name;
    private String password;
    private double balance;

    public static void welcome() {
        System.out.println(bankName + "欢迎您的到来！");
    }

    public static void welcomeNext() {
        System.out.println("请收好您的证件和物品，欢迎您下次光临！");
    }

    public BankBusiness(String name, String password) {
        this.name = name;
        this.password = password;
    }

    public void deposit() {
        Scanner sc1 = new Scanner(System.in);
        String input = sc1.next();
        double dep = sc1.nextDouble();
        if (this.password.equals(input)) {
            this.balance += dep;
            System.out.println("您的余额有" + this.balance + "元。");
        } else {
            System.out.println("您的密码错误！");
        }
    }

    public void withdraw() {
        Scanner sc2 = new Scanner(System.in);
        String input = sc2.next();
        double wit = sc2.nextDouble();
        if (this.password.equals(input)) {
            if (this.balance < wit) {
                System.out.println("您的余额不足！");
            } else {
                this.balance -= wit;
                System.out.println("请取走钞票，您的余额还有" + this.balance + "元。");
            }
        } else {
            System.out.println("您的密码错误！");
        }
    }
}

class Tools{
    private int chinese;
    private int math;
    private int science;

    public Tools(int chinese, int math, int science) {
        this.chinese = chinese;
        this.math = math;
        this.science = science;
    }

    private int getAvg(){
        return (this.chinese + this.math + this.science) / 3;
    }

    public void showAvg(){
        System.out.println("你的平均分=" + this.getAvg());
    }
}

class Student implements Comparable<Student>{
    private int num;
    private String name;
    private int height;
    private int weight;

    @Override
    public int compareTo(Student o) {
        return this.height - o.height;
    }

    public Student(int num, String name, int height, int weight) {
        this.num = num;
        this.name = name;
        this.height = height;
        this.weight = weight;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public int getWeight() {
        return weight;
    }

    public void setWeight(int weight) {
        this.weight = weight;
    }

    @Override
    public String toString() {
        return String.format("%06d", this.num)
                + " " + this.name + " "
                + this.height + " " + this.weight;
    }
}

class Student1 implements Comparable<Student1>{
    private String name;
    private int a;
    private int b;
    private int c;

    public Student1(String name, int a, int b, int c) {
        this.name = name;
        this.a = a;
        this.b = b;
        this.c = c;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getA() {
        return a;
    }

    public void setA(int a) {
        this.a = a;
    }

    public int getB() {
        return b;
    }

    public void setB(int b) {
        this.b = b;
    }

    public int getC() {
        return c;
    }

    public void setC(int c) {
        this.c = c;
    }

    public double getAver() {
        return (a + b + c) / 3.0;
    }

    @Override
    public String toString() {
        return name + " " + a + " " + b +
                " " + c + " "
                + String.format("%.2f", getAver());
     }

    @Override
    public int compareTo(Student1 o) {
        return (int)this.getAver() - (int)o.getAver();
    }
}

class Studen implements Comparable<Studen>
{
    String name;
    String birthday;
    String studentId;
    String school;
    @Override
    public int compareTo(Studen o) {
        return studentId.compareTo(o.studentId);
    }

    @Override
    public String toString() {
        return "Student[name=" + name + ", birthday=" + birthday +
                ", studentId=" + studentId
                + ", school=" + school + "]";
    }

    public Studen(String name, int year, int month, int day, String studentId, String school) {
        this.name = name;
        this.birthday = String.format("%02d", year) +
                "-" + String.format("%02d", month)
                + "-" + String.format("%02d", day);
        this.studentId = studentId;
        this.school = school;
    }
}
public class Main {
    //7-66 程序改错4：将字符串中的数字字符重新组成字符串,并转换成对应的数值输出
    public static void main(String[] args) {
        String s = "cccbaidh";
        int index = s.lastIndexOf("ab");
        System.out.println(index);
    }
    //7-65 编写程序，实现字符串大小写的转换并倒序输出。
    public static void main25(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] >= 'a' && chars[i] <='z') {
                chars[i] -= 32;
            } else if (chars[i] <= 'Z' && chars[i] >= 'A') {
                chars[i] += 32;
            }
        }
        for (int i = chars.length - 1; i >= 0; i--) {
            System.out.print(chars[i]);
        }
        sc.close();
    }
    //7-64 分析学号
    public static void main24(String[] args) {
        Scanner sc = new Scanner(System.in);
        String id = sc.next();
        String k = "";
        for (int i = 0; i < 4; i++) {
            k += id.charAt(i);
        }
        switch (k) {
            case "5001":
                System.out.println(id + " 计算机科学与技术");
                break;
            case "5013":
                System.out.println(id + " 信息安全");
                break;
                case "5004":
                System.out.println(id + " 数字媒体技术");
                break;
                case "5005":
                System.out.println(id + " 网络工程");
                break;
            case "5006":
                System.out.println(id + " 物联网工程");
                break;
            default:
                System.out.println("no exist");
        }
    }
    //7-63 定义学生类覆盖Object中的方法实现Comparable接口
    public static void main23(String[] args) {
        Scanner in=new Scanner(System.in);
        int num=in.nextInt();
        Studen[] studentArray = new Studen[num];
        for(int i=0;i<num;i++)
        {
            String name=in.next();
            int year=in.nextInt();
            int month=in.nextInt();
            int day=in.nextInt();
            String studentId=in.next();
            String school=in.next();
            studentArray[i]=new Studen(name,year,month,day,studentId,school);
        }

        Arrays.sort(studentArray);
        for(Studen s:studentArray)
            System.out.println(s);
    }
    //7-61 求某位同学的平均分
    public static int getAvg(String name, int a, int b, int c) {
        return (a + b + c) / 3;
    }
    public static int getAvg(String name, int a, int b, int c, int d) {
        return (a + b + c + d) / 4;
    }

    public static void main22(String[] args) {
        Scanner sc = new Scanner(System.in);
        String name1 = sc.next();
        int a1 = sc.nextInt();
        int b1 = sc.nextInt();
        int c1 = sc.nextInt();
        String name2 = sc.next();
        int a2 = sc.nextInt();
        int b2 = sc.nextInt();
        int c2 = sc.nextInt();
        int d = sc.nextInt();
        System.out.println(name1 + ":" + getAvg(name1, a1, b1, c1));
        System.out.println(name2 + ":" + getAvg(name2, a2, b2, c2, d));
    }
    //7-60 平均成绩
    public static void main21(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Student1[] s = new Student1[n];
        for (int i = 0; i < n; i++) {
            Student1 student1 = new Student1(sc.next(), sc.nextInt(), sc.nextInt(), sc.nextInt());
            if (student1.getAver() >= 60) {
                s[i] = student1;
            }
        }
//        Arrays.sort(s);
        for (int i = n - 1; i > -1; i--) {
            if (s[i] != null) {
                System.out.println(s[i]);
            }
        }
    }
    //7-59 宿舍谁最高？
    public static void main20(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Student[] student = new Student[999999 + 1];
        for (int i = 0; i < n; i++) {
            Student student1 = new Student(sc.nextInt(),
                    sc.next(), sc.nextInt(), sc.nextInt());
            if (student[student1.getNum()] == null) {
                student[student1.getNum()] = student1;
            } else if (student[student1.getNum()].getHeight() < student1.getHeight()) {
                student[student1.getNum()] = student1;
            }
        }
        for (Student s:
             student) {
            if (s != null) {
                System.out.println(s);
            }
        }

    }
    //7-58 帮小朋友计算他的学习成绩
    public static void main19(String[] args) {
        Scanner sc = new Scanner(System.in);
        int chinese = sc.nextInt();
        int math = sc.nextInt();
        int science = sc.nextInt();
        Tools tools = new Tools(chinese, math, science);
        tools.showAvg();
    }
    //7-57 游泳池过道改造2
    public static void main18(String[] args) {
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double s = a * b - Math.PI * Math.pow(r, 2);
        double c = 2 * (a + b);
        double price1 = 35 * c;
        double price2 = 20 * s;
        System.out.println(String.format("Fencing Cost is $%.2f", price1));
        System.out.println(String.format("Concrete Cost is $%.2f", price2));
    }
    //7-56 游泳池过道改造
    public static void main17(String[] args) {
        Scanner sc = new Scanner(System.in);
        double r = sc.nextDouble();
        double s = Math.PI * Math.pow(r + 3, 2) - Math.PI * Math.pow(r, 2);
        double c = 2 * Math.PI * (r + 3);
        double price1 = c * 35;
        double price2 = s * 20;
        System.out.println(String.format("Fencing Cost is $%.2f", price1));
        System.out.println(String.format("Concrete Cost is $%.2f", price2));
    }
    //7-55 设计一个银行业务类
    public static void main16(String[] args) {
        BankBusiness.welcome();
        Scanner sc = new Scanner(System.in);
        String name = sc.next();
        String password = sc.next();
        BankBusiness account = new BankBusiness(name, password);
        account.deposit();
        account.withdraw();
        account.withdraw();
        account.withdraw();
        BankBusiness.welcomeNext();
        sc.close();
    }
    //7-54 sdut-分数加减法
    public static int commonDivisor(int b, int d) {//求最大公约数
        int big = Math.max(b, d);
        int small = Math.min(b, d);
        int tmp;
        while (small != 0) {
            tmp = big % small;
            big = small;
            small = tmp;
        }
        return big;
    }

    public static int lc(int gcd, int b, int d) {//求最小公倍数
        int big = Math.max(b, d);
        int small = Math.min(b, d);
        return (big / gcd) * small;
    }

    public static void main15(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextLine()) {
            String fm = sc.nextLine();
            int a = fm.charAt(0) - '0';
            int b = fm.charAt(2) - '0';
            int o = fm.charAt(3);
            int c = fm.charAt(4) - '0';
            int d = fm.charAt(6) - '0';
            int lcm = lc(commonDivisor(b, d), b, d);
            int molecule;
            int denominator = lcm;
            if (o == '+') {
                molecule = a * (lcm / b) + c * (lcm / d);
            } else {
                molecule = a * (lcm / b) - c * (lcm / d);
            }
            int gcd2 = commonDivisor(molecule, denominator);
            if (molecule % denominator == 0) {
                System.out.println(molecule / denominator);
            } else {
                if (molecule * denominator > 0) {
                    System.out.println(molecule / gcd2 + "/" + denominator / gcd2);
                } else {
                    System.out.println("-" + Math.abs(molecule / gcd2) + "/" + Math.abs(denominator / gcd2));
                }
            }
        }
    }
    //7-53 复数类的定义
    public static void main14(String [] args){
        Complex a=new Complex();
        Complex b=new Complex();
        Scanner in=new Scanner(System.in);
        a.setRealPart(in.nextDouble());
        a.setImaginaryPart(in.nextDouble());
        b.setRealPart(in.nextDouble());
        b.setImaginaryPart(in.nextDouble());
        System.out.println(a);
        System.out.println(b);
        System.out.println(a.add(b));
        System.out.println(a.sub(b));
    }
    //7-49 计算年龄
    public static void main13(String[] args) {
        Scanner sc = new Scanner(System.in);
        int year = sc.nextInt();
        int month = sc.nextInt();
        int day = sc.nextInt();
        Birthday birthday = new Birthday(year, month, day);
        System.out.println("age=" + birthday.getAge());
    }
    //7-48 设计一个矩形类Rectangle
    public static void main12(String[] args) {
        Scanner sc = new Scanner(System.in);
        double w1 = sc.nextDouble();
        double h1 = sc.nextDouble();
        double w2 = sc.nextDouble();
        double h2 = sc.nextDouble();
        Rectangle r1 = new Rectangle(w1, h1);
        Rectangle r2 = new Rectangle(w2, h2);
        System.out.println(r1);
        System.out.print(r2);
    }
    //7-47 统计商品总价
    public static void main11(String[] args){
        Goods ga[] =new Goods[5];
        Scanner sc = new Scanner(System.in);

        for(int i =0;i<5;i++){
            ga[i]= new Goods(sc.next(),sc.nextDouble());
        }

        double  shouldPay = 0;
        for(Goods g:ga){
            shouldPay += g.getPrice();
            System.out.println(g.toString());
        }

        System.out.println("should pay:"+shouldPay);
    }
    //7-45 定义商品类，封装成员变量，输出对象
    public static void main10(String[] args) {
        Scanner sc = new Scanner(System.in);
        String num = sc.next();
        String name = sc.next();
        double price = sc.nextDouble();
        Good good = new Good(num, name, price);
        System.out.println(good);
    }
    //7-44 整数数组比较
    public static void main9(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            b[i] = a[i];
        }
        Arrays.sort(b);
        int count1 = 0;
        int count2 = 0;
        int count3 = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] > b[i]) {
                count1++;
            } else if (a[i] < b[i]) {
                count3++;
            } else {
                count2++;
            }
        }
        System.out.println(count1);
        System.out.println(count2);
        System.out.println(count3);
    }
    //7-43 矩阵运算
    public static void main8(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] array1 = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                array1[i][j] = sc.nextInt();
            }
        }
        int add = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i + j != n - 1 && j != n - 1 && i != n -1) {
                    add += array1[i][j];
                }
            }
        }
        System.out.print(add);
    }
    //7-41 期末分数排序
    public static void main7(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array.length - i - 1; j++) {
                if (array[j] < array[j + 1]) {
                    int tmp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = tmp;
                }
            }
        }
        System.out.print(array[0]);
        for (int i = 1; i < array.length; i++) {
            System.out.print(" " + array[i]);
        }
    }
    //7-40 评委打分
    public static void main6(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] array = new int[10];
        for (int i = 0; i < 10; i++) {
            array[i] = sc.nextInt();
        }
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            int k = sc.nextInt();
            array[k - 1] += 10;
        }
        System.out.print(array[0]);
        for (int i = 1; i < 10; i++) {
            System.out.print(" "  + array[i]);
        }
    }
    //7-39 去掉重复的数据
    public static void main5(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array1 = new int[n];
        for (int i = 0; i < n; i++) {
            array1[i] = sc.nextInt();
        }
        int[] array2 = new int[100005];
        int count = 0;
        for (int i = 0; i < array1.length; i++) {
            if (array2[array1[i]] == 0) {
                if (count == 0) {
                    System.out.print(array1[i]);
                    count++;
                } else {
                    System.out.print(" " + array1[i]);
                }
                array2[array1[i]]++;
            }
        }
    }
    //7-38 整理队伍
    public static void swap(int[] array, int x, int y) {
        int tmp = array[x - 1];
        array[x - 1] = array[y - 1];
        array[y - 1] = tmp;
    }
    public static void main4(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        int k = sc.nextInt();
        for (int i = 0; i < k; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            swap(array, x, y);
        }
        System.out.print(array[0]);
        for (int i = 1; i < array.length; i++) {
            System.out.print(" " + array[i]);
        }
    }
    //7-37 数组元素移动
    public static void move(int[] array, int y) {
        int k = array[y];
        for (int i = y; i < array.length - 1; i++) {
            array[i] = array[i + 1];
        }
        array[array.length - 1] = k;
    }
    public static void main3(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        int x = sc.nextInt();
        for (int i = 0; i < x; i++) {
            int y = sc.nextInt();
            move(array, y - 1);
        }
        System.out.print(array[0]);
        for (int i = 1; i < array.length; i++) {
            System.out.print(" " + array[i]);
        }
    }
    //7-36 sdut-array1-3 显示缺失的数
    public static void main2(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n + 1];
        array[0] = 1;
        int num = 0;
        while ((num = sc.nextInt()) != 0){
            array[num]++;
        }
        int count = 0;
        for (int i = 0; i < array.length; i++) {
            if (array[i] == 0) {
                System.out.print(i + " ");
                count++;
            }
        }
        if (count == 0) {
            System.out.print("FULL");
        }
    }
    //7-35 方阵转置
    public static void main1(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] array1 = new int[n][n];
        int[][] array2 = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                array1[i][j] = sc.nextInt();
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                array2[j][i] = array1[i][j];
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                System.out.printf("%4d", array2[i][j]);
            }
            System.out.println();
        }
    }
}
